home *** CD-ROM | disk | FTP | other *** search
- /* sample of menu functions */
- #include <stdio.h>
- #include "wwindefs.h" /* window headers */
- #include "wwinstpr.h"
-
- /* subroutine prototypes */
- void LoadUpMenus();
- int DoMenus();
- void DialHandler(struct WWinRC ret);
-
- extern WWVIDMEM WWscreenp; /* pointer to screen memory */
- extern unsigned int WWScreenLength; /* access to WW default */
-
-
- /* define caption window - globally */
- struct WWinstruc Caption =
- {"Caption",20,5,10,60, WHITE,BLACK,SLN_BDR,WHITE,BLACK,INV_CSR};
-
- /* define the menu windows */
- struct WWinstruc TopLine =
- {"TopLine",1,1,2,70, RED,WHITE,NO_BDR,0,0,INV_CSR};
- struct WWinstruc DropWin[6] = {
- {"File",3,9,4,15,BLUE,WHITE,SLN_BDR,WHITE,BLUE,INV_CSR},
- {"Baud",3,6,11,5,BLUE,WHITE,SLN_BDR,WHITE,BLUE,INV_CSR},
- {"Parity",3,3,22,5,BLUE,WHITE,SLN_BDR,WHITE,BLUE,INV_CSR},
- {"Transfer",3,5,31,11,BLUE,WHITE,SLN_BDR,WHITE,BLUE,INV_CSR},
- {"Error",3,2,42,6,BLUE,WHITE,SLN_BDR,WHITE,BLUE,INV_CSR},
- {"Dial",3,4,49,30,BLUE,WHITE,SLN_BDR,WHITE,BLUE,INV_CSR} };
-
- unsigned int *hold_Dial_mem_ptr; /* hold for Dial Memorypointer */
- /* Dial window is mapped on dial #s */
- main()
- {
- int i, rc;
- WWscreenp = WWCOLMEM; /* unecessary - color screen memory is default */
- for (i=0;i<27;i++) /* clear screen */
- printf(" "
- " ");
- if ((rc = WWinDef(&Caption)) !=0) /* set up caption screen */
- {printf("out of memory"); exit(1);}
-
- WWinLoad(&Caption,1,2,NC,NC,"Press arrow keys, ENTER, or hilited char",0);
- WWinLoad(&Caption,2,2,NC,NC,"Pick an item from a drop down menu"
- " - scroll Dial menu",0);
- WWinLoad(&Caption,3,2,NC,NC,"Press ESC to exit this program",0);
- WWinPut(&Caption);
- WWinCurSet(&Caption,1,1); /* set cursor out of the way */
-
- LoadUpMenus(); /* load menu items into windows */
- do
- {
- rc = DoMenus(); /* process menues */
- }
- while (rc != 27);
- Caption.Cursor = NRM_CSR; /* set cursor back to normal */
- WWinCurSet(&Caption,Caption.UseLength,1); /* restore cursor */
- }
-
-
-
- void LoadUpMenus()
- /* this function loads the various windows with menu items and
- * sets hilited chracters. Each menu item in the vertical menus is
- * followed by a 2-digit offset of the hilited character. The
- * hilited chars in the horizontal menus are indicated by a following
- * string that contains dashes where the hilited character is to appear.
- */
- {
- unsigned char TopMenu[2][56] =
- {"File Baudrate Parity Transfer Error Dial",
- "- - - - - - "};
- unsigned char *FileMenu[] =
- { " New 02", /* hilite 2nd pos */
- " Open 02", /* " */
- " Open Last File 12", /* hilite 12th pos */
- " Merge 02",
- " Save 02",
- " Save As 07",
- " 00", /* space for divider */
- " Dos Shell 02",
- " Exit 03"};
- unsigned char Double_Divider[15] = /* dbl divider chars */
- {205,205,205,205,205,205,205,205,205,205,205,205,205,205,205};
- unsigned char *BaudMenu[] =
- { " 300 03",
- " 1200 02",
- " 2400 02",
- " 4800 02",
- " 9600 02",
- " 19.2 04"};
- unsigned char *ParityMenu[] =
- { " Even 02",
- " Odd 02",
- " None 02"};
- unsigned char *TransferMenu[] =
- { " Blind 02",
- " Kermit 02",
- " Protocol A 11",
- " Protocol B 11",
- " Protocol Z 11"};
- unsigned char *ErrorMenu[] =
- { " Retry 02",
- " Abort 02"};
- unsigned char *DialMenu[] =
- {" Work 123-456-7890", /* no hilite */
- " BBS #1 234-567-8901", " BBS #2 345-678-9012",
- " BBS #3 234-567-8901", " BBS #4 345-678-9012",
- " BBS #5 234-567-8901", " BBS #6 345-678-9012",
- " BBS #7 234-567-8901", " BBS #8 345-678-9012",
- " BBS #9 234-567-8901", " BBS #10 345-678-9012",
- " BBS #11 234-567-8901", " BBS #12 345-678-9012",
- " BBS #13 234-567-8901", " BBS #14 345-678-9012",
- " BBS #15 234-567-8901", " BBS #16 345-678-9012",
- " BBS #17 234-567-8901", " BBS #18 345-678-9012",
- " BBS #19 234-567-8901", " BBS #20 345-678-9012",
- " BBS #21 234-567-8901", " BBS #22 345-678-9012",
- " BBS #23 234-567-8901", " BBS #24 345-678-9012",
- " BBS #25 234-567-8901", " BBS #26 345-678-9012"};
- char inkey, *menuptr[6];
- int i, j, k, rc;
-
- menuptr[0] = &FileMenu[0][0]; /* build array of array pointers */
- menuptr[1] = &BaudMenu[0][0];
- menuptr[2] = &ParityMenu[0][0];
- menuptr[3] = &TransferMenu[0][0];
- menuptr[4] = &ErrorMenu[0][0];
-
- /* load topline */
- if ((rc = WWinDef(&TopLine)) !=0)
- {printf("out of memory"); exit(1);}
- WWinLoad(&TopLine,1,2,NC,NC,TopMenu[0],0); /* load text */
- for (i=0; i < 56;i++) /* load hilited chars */
- if (TopMenu[1][i] == '-')
- WWinLoad(&TopLine,1,2+i,NC,NCB,NULL,1);
- WWinPut(&TopLine);
-
- /* load all vertical menus except phone directory */
- for (i=0;i<5;i++) /* for each window */
- {
- if ((rc = WWinDef(&DropWin[i])) !=0) /* define window */
- {printf("out of memory"); exit(1);}
- for (j=0;j<DropWin[i].UseLength;j++) /* for each window row */
- { /* load the text */
- WWinLoad(&DropWin[i],j+1,1,NC,NC,
- menuptr[i]+j*(DropWin[i].UseWidth+4),DropWin[i].UseWidth);
- /* calc the hilite offset */
- k = atoi(menuptr[i]+j*(DropWin[i].UseWidth+4)+DropWin[i].UseWidth+1);
-
- if (k != 0) /* hilite the char */
- WWinLoad(&DropWin[i],j+1,k,NC,NCB,NULL,1);
- }/*for j*/
- }/*for i*/
- /* load double-line divider in 1st drop window */
- WWinLoad(&DropWin[0],7,0,NC,NC,"\xc6",1); /* |= */
- WWinLoad(&DropWin[0],7,1,NC,NC,Double_Divider,15); /* = */
- WWinLoad(&DropWin[0],7,DropWin[0].UseWidth+1,NC,NC,"\xb5",1); /* =| */
-
- /* load the phone directory
- * there are more menu items (27) than will fit on a screen.
- * must load all items, then scroll up and down
- */
- WWScreenLength = 30; /* trick WW into assigning enough */
- DropWin[5].UseLength = 27; /* window-memory for table */
- if ((rc = WWinDef(&DropWin[5])) !=0) /* define window */
- {printf("out of memory"); exit(1);}
- for (j=0;j<27;j++) /* load the text */
- WWinLoad(&DropWin[5],j+1,1,NC,NC, DialMenu[j],30);
- WWScreenLength = 25; /* correct the screen length */
- DropWin[5].UseLength = 4; /* correct the window length */
- WWinBorder(&DropWin[5]); /* correct the border */
- WWinLoad(&DropWin[5],DropWin[5].UseLength+1, /* write to border */
- 12,NC,NC,"scroll",0);
- /* store original memorypointer for test limit and later free */
- hold_Dial_mem_ptr = DropWin[5].MemoryPointer;
- }/* end function LoadUpMenus */
-
-
-
-
- int DoMenus()
- /* this function handles the presentation of the horizontal and
- * drop-down menus and keeps track of what items were chosen.
- */
- {
- struct WWinRC retcde;
- int i, activetop, activedrop, horizitem, done;
- char horizchar, picked[40];
-
- done = 0;
- activetop = 1; /* start with first item */
- while (!done) /* loop till done != 0 */
- {
- do /* horizontal menu processing */
- {
- retcde = WWinHmenu(&TopLine,1,BLACK,NC,BRIGHT|LOOP,activetop);
- activetop = retcde.exval;
- if (retcde.scan == 80) /* if down-arrow, force ENTER */
- WWinStack("0,13,0"); /* by stacking ENTER codes */
- }
- while (retcde.ascii == 0); /* end horiz menu */
-
- if (retcde.ascii == 27) return(27); /* get out */
-
- /* display drop down menu */
- horizchar = retcde.ascii;
- horizitem = retcde.exval-1;
- WWinPut(&DropWin[horizitem]);
- activedrop = 1;
- do /* vertical menu procesing */
- {
- if (horizchar == 'D') /* Dial? */
- retcde = WWinVmenu(&DropWin[horizitem],BLACK,NC,NOLOOP,activedrop);
- else
- retcde = WWinVmenu(&DropWin[horizitem],BLACK,NC,
- BRIGHT|LOOP,activedrop);
- activedrop = retcde.exval;
- if (retcde.scan == 75)
- { /* left-arrow - shift to prev drop menu */
- WWinStack("75,0,0,0,13,0"); /* stack left-arrow and ENTER codes */
- retcde.ascii = 27;
- }
- if (retcde.scan == 77)
- { /* right-arrow - shift to next drop menu */
- WWinStack("77,0,0,0,13,0"); /* stack right-arrow and ENTER codes */
- retcde.ascii = 27;
- }
- if (horizchar == 'D') /* Dial? */
- DialHandler(retcde);
- }
- while (retcde.ascii == 0); /* end vert menu processing */
-
- if (retcde.ascii != 27) /* was drop item chosen? */
- done = 1;
- WWinErase(&DropWin[horizitem]);
- }/* while not done */
- /* drop item WAS chosen */
- WWinRead(&DropWin[horizitem],retcde.exval,1,
- picked,DropWin[horizitem].UseWidth);
- WWinLoad(&Caption,5,2,BLACK,WHITE,
- "You picked hilited char x dropmenu item ",0);
- WWinLoad(&Caption,5,27,NC,NC,&horizchar,1);
- WWinLoad(&Caption,5,45,NC,NC,picked,0);
- WWinPut(&Caption);
- return(0);
- }/* end DoMenus */
-
-
-
-
- void DialHandler(struct WWinRC ret)
- /* this function handles the scrolling for the Dial window.
- * The Dial window is only 4 rows long, but there are 27 displayable
- * items. The NOLOOP option forced an exit when an attempt was made to
- * scroll up or down.
- */
- {
- int Diallength;
- Diallength = 27; /* length of array */
-
- if (ret.scan == 72) /* up arrow */
- if (DropWin[5].MemoryPointer > hold_Dial_mem_ptr)
- {
- DropWin[5].MemoryPointer -= DropWin[5].UseWidth;
- }
- if (ret.scan == 80) /* down arrow */
- if (DropWin[5].MemoryPointer
- < hold_Dial_mem_ptr
- + (Diallength-DropWin[5].UseLength)*DropWin[5].UseWidth)
- {
- DropWin[5].MemoryPointer += DropWin[5].UseWidth;
- }
- if (ret.scan == 73) /* page up */
- {
- DropWin[5].MemoryPointer -= DropWin[5].UseLength*DropWin[5].UseWidth;
- if (DropWin[5].MemoryPointer < hold_Dial_mem_ptr)
- DropWin[5].MemoryPointer = hold_Dial_mem_ptr;
- }
- if (ret.scan == 81) /* page down */
- {
- DropWin[5].MemoryPointer += DropWin[5].UseLength*DropWin[5].UseWidth;
- if (DropWin[5].MemoryPointer
- > hold_Dial_mem_ptr
- + (Diallength-DropWin[5].UseLength)*DropWin[5].UseWidth)
- DropWin[5].MemoryPointer
- = hold_Dial_mem_ptr
- + (Diallength-DropWin[5].UseLength)*DropWin[5].UseWidth;
- }
- WWinPut(&DropWin[5]);
- }
-